package com.jwsoft.manager.common.vo.eduAddressTree;

import com.baomidou.mybatisplus.annotation.TableField;
import com.bifang.assistant.common.vo.BaseVO;
import com.jwsoft.manager.common.enums.DataSaveEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * VO,用于缓存修改操作
 *
 * @author fangs
 * @since 2023-02-03
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Schema(name = "EduAddressTreeVO", title = "VO", description = "实体类")
public class EduAddressTreeVO extends BaseVO {


    private static final String EDU_ADDRESS_ID_SEPARATOR = ",";

    @Schema(name = "addressId", title = "地址id")
    private Long addressId;

    @Schema(name = "areaCode", title = "行政区划编码")
    private String areaCode;

    @Schema(name = "areaName", title = "组织名称")
    private String areaName;

    @Schema(name = "areaType", title = "行政区划类型 ")
    private String areaType;

    @Schema(name = "contact", title = "联系人")
    private String contact;

    @Schema(name = "cellphone", title = "联系人手机")
    private String cellphone;

    @Schema(name = "phone", title = "联系人电话")
    private String phone;

    @Schema(name = "rate", title = "级别")
    private Integer rate;

    @Schema(name = "orderNo", title = "排序号")
    private Integer orderNo;

    @Schema(name = "primarySchool", title = "小学默认学校组织id")
    private String primarySchool;

    @Schema(name = "middleSchool", title = "中学默认学校组织id")
    private String middleSchool;

    @Schema(name = "checkPrimaryList", title = "小学默认学校组织id列表")
    private List<String> checkPrimaryList;

    @Schema(name = "middleSchool", title = "中学默认学校组织id列表")
    private List<String> checkMiddleList;

    /**
     * 以下字段用于缓存修改操作
     */
    @Schema(name = "oldParentId", title = "前上级地址/区域")
    private Long oldParentId;

    @Schema(name = "parentId", title = "上级地址/区域")
    private Long parentId;

    @Schema(name = "searchTerm", title = "检索项，使用#分割")
    private String searchTerm;

    @Schema(name = "leafNode", title = "是否叶子节点")
    private Integer leafNode;

    @Schema(name = "fullAddress", title = "完整地址信息")
    private String fullAddress;

    @Schema(name = "majorPointer", title = "映射记录指针，对应映射记录主键address_id")
    private Long majorPointer;

    @Schema(name = "eduAddressId", title = "edu_address主键")
    private String eduAddressId;

    @Schema(name = "lastNode", title = "是否最后非叶子节点-es数据检索节点")
    private Integer lastNode;

    @Schema(name = "esStatus", title = "0:未存到es,1:已保存到es")
    private Integer esStatus;

    @Schema(name = "esMsg", title = "es状态描述")
    private String esMsg;

    @Schema(name = "esTime", title = "保存es时间")
    private Date esTime;

    @Schema(name = "change_node", title = "是否变更")
    private Integer changeNode;

    @Schema(name = "changeType", title = "数据变更类型")
    private DataSaveEnum changeType;

    @Schema(name = "leafNum", title = "叶子节点数")
    private Integer leafNum;

    @Schema(name = "affirmFlag", title = "地址节点是否确认标志：0 未确认，1 确认")
    private Integer affirmFlag;

    public List<String> getEduAddressIdList() {
        if (StringUtils.isBlank(eduAddressId)) {
            return new ArrayList<>(0);
        }
        return new ArrayList<>(Arrays.asList(eduAddressId.split(EDU_ADDRESS_ID_SEPARATOR)));
    }
}
